package commands

import (
	"github.com/gookit/color"
	"github.com/goravel/framework/contracts/console"
	"github.com/goravel/framework/contracts/console/command"
	"github.com/goravel/framework/database/gorm"
	"github.com/goravel/framework/facades"
)

type MigrateTable struct {
	Models []any
}

// Signature The name and signature of the console command.
func (receiver *MigrateTable) Signature() string {
	return "migrate:table"
}

// Description The console command description.
func (receiver *MigrateTable) Description() string {
	return "根据model文件创建数据库表"
}

// Extend The console command extend.
func (receiver *MigrateTable) Extend() command.Extend {
	return command.Extend{
		Category: "migrate",
	}
}

// Handle Execute the console command.
func (receiver *MigrateTable) Handle(ctx console.Context) error {

	for _, model := range receiver.Models {
		facades.Orm().Query().(*gorm.QueryImpl).Instance().AutoMigrate(model)
	}

	color.Greenln("创建成功")
	return nil
}
